#include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
void play_game() {
    int secret = rand() % 100 + 1;  // 生成一个1到100之间的随机
    int guess = 0;
 
    printf("Welcome to the number guessing game!\n");
    printf("I'm thinking of a number between 1 and 100.\n");
 
    while (1) {
        printf("Enter a guess: ");
        scanf("%d", &guess);
 
        if (guess == secret) {
            printf("Congratulations, you guessed it!\n");
            break;
        } else if (guess < secret) {
            printf("Too low, try again.\n");
        } else {
            printf("Too high, try again.\n");
        }
    }
}
 
int main() {
    srand(time(0));  
    play_game();
    return 0;
}